package thread05;

public class Ticket implements Runnable{
    private int ticket = 100; // 初始化100张票
    @Override
    public void run() {
        // 卖票
        while(true){
            if(ticket>0){
                try {
                    Thread.sleep(100); // sleep()需要try...catch解决异常
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                // 打印票数，然后自减，就是卖一张票后自减
                System.out.println(Thread.currentThread().getName()+"..."+ticket--);}
        }
    }
}
